home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / env / dynenv.sml < prev    next >
Encoding:
Text File  |  1993-01-27  |  1.4 KB  |  43 lines

  1. (* Copyright 1989 by AT&T Bell Laboratories *)
  2. (* dynenv.sml *)
  3.  
  4. structure DynamicEnv : DYNENV =
  5. struct
  6.  
  7.   type object = System.Unsafe.object
  8.   datatype dynenv = NORM of System.Unsafe.object IntmapF.intmap * dynenv
  9.                   | SPECIAL of (Access.lvar -> System.Unsafe.object) * dynenv
  10.           | EMPTY
  11.   (* chain invariant: only one NORM in a row. *)
  12.  
  13.   exception Unbound = IntmapF.IntmapF
  14.   exception SpecialEnv
  15.  
  16.   val empty = EMPTY
  17.  
  18.   fun special (f,next) = SPECIAL(f,next)
  19.  
  20.   fun look (NORM(map,next)) lv = ((IntmapF.lookup map lv)
  21.                   handle Unbound => look next lv)
  22.     | look (SPECIAL(f,next)) lv = ((f lv) handle Unbound => look next lv)
  23.     | look EMPTY lv = raise Unbound
  24.  
  25.   fun bind (lv,binding,NORM(map,next)) = NORM(IntmapF.add(map,lv,binding),next)
  26.     | bind (lv,binding,x) = NORM(IntmapF.add(IntmapF.empty,lv,binding),x)
  27.  
  28.   fun atop(NORM(topmap,EMPTY),NORM(bottommap,next)) = 
  29.       NORM(IntmapF.overlay(topmap,bottommap),next)
  30.     | atop(NORM(topmap,EMPTY),bottom) = NORM(topmap,bottom)
  31.     | atop(NORM(topmap,nexttop),bottom) = NORM(topmap,atop(nexttop,bottom))
  32.     | atop(SPECIAL(f,nexttop),bottom) = SPECIAL(f,atop(nexttop,bottom))
  33.     | atop(EMPTY,bottom) = bottom
  34.        
  35.   fun remove(lvars: Access.lvar list, NORM(map,next)) =
  36.       NORM(fold IntmapF.delete lvars map,remove(lvars,next))
  37.     | remove(lvars,SPECIAL(f,next)) = raise SpecialEnv
  38.     | remove(lvars,EMPTY) = EMPTY
  39.       
  40.   fun consolidate e = e
  41.  
  42. end (* structure DynamicEnv *)
  43.